package main

import (
	"fmt"
	"io"
	"net/http"
)

func main() {
	testClientGet()
}
func testClientGet() {
	//创建客户端
	client := http.Client{}
	//通过client去请求
	response, err := client.Get("http://127.0.0.1:9090/login?name=zhb&age=18")
	CheckErr(err)
	fmt.Printf("响应状态码: %v\n", response.StatusCode)

	if response.StatusCode == 200 {
		fmt.Println("网络请求成功")
		defer response.Body.Close()
		//处理
		data, err := io.ReadAll(response.Body)
		CheckErr(err)
		fmt.Println(string(data))
	}
}

// 检查错误
func CheckErr(err error) {
	//fmt.Println("09---------------")
	defer func() {
		if ins, ok := recover().(error); ok {
			fmt.Println("程序出现异常：", ins.Error())
		}
	}()
	if err != nil {
		panic(err)
	}
}
